package com.imooc.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@ApiIgnore
@RestController
public class HelloController {

    final static Logger logger = LoggerFactory.getLogger(HelloController.class);


    @GetMapping("/hello")
    public Object hello() {

        logger.debug("debug:hello~");
        logger.info("info:hello~");
        logger.warn("warn:hello~");
        logger.error("error:hello~");

        return "hello word";
    }

    @GetMapping("/setSession")
    public Object setSession(HttpServletRequest httpServletRequest) {
        HttpSession session = httpServletRequest.getSession();
        session.setAttribute("userInfo", "new user"); //设置session的键值对
        session.setMaxInactiveInterval(3600); //设置session的过期时间
        session.getAttribute("userInfo"); //获取session的值
        session.removeAttribute("userInfo"); //移除session的键值对
        return "ok";

    }

}
